<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<link rel="stylesheet" href="<%=path%>/css/pintuer.css">
<link rel="stylesheet" href="<%=path%>/css/admin.css">
<link rel="shortcut icon" href="<%=path%>/images/login.jfif">
<script src="<%=path%>/js/jquery.js"></script>
<script type="text/javascript">
	
</script>

</head>

<body>
	<div class="panel admin-panel">
		<div class="panel-head" id="add">
			<strong><span class="icon-pencil-square-o"></span>增加家庭档案</strong>
		</div>
		<div class="body-content">
			<form id="form-addrole" method="post" class="form-x">
			
			<div class="form-group">
					<div class="label">
						<label>户主姓名：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.member_name}" 
							name="member_name" id="member_name_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>身份证号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.people_id}" disabled="disabled"
							name="people_id" id="people_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>医疗证号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.medical_card_id}" disabled="disabled"
							name="medical_card_id" id="medical_card_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				
				<div class="form-group">
					<div class="label">
						<label>农合证号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.rural_id}" disabled="disabled"
							name="rural_id" id="rural_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>户内编号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.member_id}"
							name="member_id" id="member_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>与户主关系：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.relation}"
							name="relation" id="relation_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>家庭住址：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${family.family_adress}"
							name="family_adress" id="family_adress_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>家庭编号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${family.family_id}" disabled="disabled"
							name="family_id" id="family_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>所属县级行政区域：</label>
					</div>
					<div class="field">
						<select id="area_county_id" class="input w50" name="area_county_id">
							<option value="0">选择行政区域</option>
						</select>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>所属乡镇：</label>
					</div>
					<div class="field">
						<select id="area_town_id" class="input w50" name="area_town_id">
							<option value="0">选择乡镇</option>
						</select>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>所属村：</label>
					</div>
					<div class="field">
						<select id="area_village_id" class="input w50" name="area_village_id">
							<option value="0">选择村</option>
						</select>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>所属组：</label>
					</div>
					<div class="field">
						<select id="area_team_id" class="input w50" name="area_team_id">
							<option value="0">选择组</option>
						</select>
						<div class="tips"></div>
					</div>
				</div>
				
				
				
				<div class="form-group">
					<div class="label">
						<label></label>
					</div>
					<div class="field">
						<button id="add_btn" class="button bg-main icon-check-square-o"
							onclick="updateFamily()" type="button">提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>

</body>
<script type="text/javascript">
	//异步加载县级行政区域信息
	$(document).ready(function() {
		$.ajax({
			type : "post",
			datatype : "json",
			url : "<%=path%>/area/area_loadAreaWithCounty",
			async : false,
			success : function(result) {
				$.each(result.extend.countylist, function() {
					var optionEle = $("<option></option>").append(this.area_name).attr("value", this.area_id);
					optionEle.appendTo("#area_county_id");
				})

			}
		})
	});
	//异步加载乡镇级行政区域信息
	$("#area_county_id").change(function(){
	  var father_id = $("#area_county_id").val();
	     $.ajax({
	          url:"<%=path%>/area/area_loadAreaWithFatherId",
	          type:"post",
	          data:{father_id:father_id},
	          success:function(result){
	          $.each(result.extend.childarealist, function() {
					var optionEle = $("<option></option>").append(this.area_name).attr("value", this.area_id);
					optionEle.appendTo("#area_town_id");
				})
	          }
	     })
	})
	//异步加载组级行政区域信息
	$("#area_town_id").change(function(){
	 var father_id = $("#area_town_id").val();
	    $.ajax({
	        url:"<%=path%>/area/area_loadAreaWithFatherId",
	        type:"post",
	        data:{father_id:father_id},
	        success:function(result){
	          $.each(result.extend.childarealist, function() {
					var optionEle = $("<option></option>").append(this.area_name).attr("value", this.area_id);
					optionEle.appendTo("#area_village_id");
				})
	          }
	    })
	})
	//异步加载组级行政区域信息
	$("#area_village_id").change(function(){
	 var father_id = $("#area_village_id").val();
	    $.ajax({
	        url:"<%=path%>/area/area_loadAreaWithFatherId",
	        type:"post",
	        data:{father_id:father_id},
	        success:function(result){
	          $.each(result.extend.childarealist, function() {
					var optionEle = $("<option></option>").append(this.area_name).attr("value", this.area_id);
					optionEle.appendTo("#area_team_id");
				})
	          }
	    })
	})
	//校验户主是否已经登记
	$("#people_id_input").change(function(){
	 var people_id = this.value;
	   $.ajax({
	          url:"<%=path%>/member/member_check",
	          type:"post",
	          data:{people_id:people_id},
	          success:function(result){
	          
	          	if (result.code == 100) {
					show_validate_msg("#people_id_input", "success", "该身份证可注册");
				} else {
					show_validate_msg("#people_id_input", "error", "该身份证已注册家庭档案！");
				}
	          }
	   })
	})
	//更新家庭档案信息
	function updateFamily() {
		var member_name = $("#member_name_input").val();
		var people_id = $("#people_id_input").val();
		var medical_card_id = $("#medical_card_id_input").val();
		var rural_id = $("#rural_id_input").val();
		var member_id = $("#member_id_input").val();
		var relation = $("#relation_input").val();
		
		var family_adress = $("#family_adress_input").val();
		var family_id = $("#family_id_input").val();
		var area_county_id = $("#area_county_id").val();
		var area_town_id = $("#area_town_id").val();
		var area_village_id = $("#area_village_id").val();
		var area_team_id = $("#area_team_id").val();
		$.ajax({
			type : "post",
			url : "<%=path%>/family/family_update_action",
			data : {
				member_name: member_name,
				people_id: people_id,
				medical_card_id: medical_card_id,
				rural_id: rural_id,
				member_id:member_id,
				relation:relation,
				family_adress:family_adress,
				family_id:family_id,
				area_county_id:area_county_id,
				area_town_id:area_town_id,
				area_village_id:area_village_id,
				area_team_id:area_team_id
				
			},
			
			success : function(result) {
			  if(result.code==100){
			     alert("修改成功！")
			  }else{
			  	  alert("修改失败！")
			  
			  }

			}
		})
	}
	//校验家庭地址是否重复
	$("#family_adress_input").change(function() {
		var family_adress = this.value;
		$.ajax({
			url : "<%=path%>/family/family_check",
			data : {family_adress:family_adress},
			type : "post",
			success : function(result) {
			console.log(result)
				if (result.code == 100) {
					show_validate_msg("#family_adress_input", "success", "该家庭地址可登记");
				} else {
					show_validate_msg("#family_adress_input", "error", "该家庭地址已经登记！");
				}
			}
		})
	});
	//校验结果提示信息
	function show_validate_msg(ele, status, msg) {
		//清除当前元素的校验状态
		$(ele).next("span").text("");
		if ("success" == status) {
			$(ele).next("span").text(msg);
		} else if ("error" == status) {
			$(ele).next("span").text(msg);
		}
	}
</script>
</html>
